package com.ita.activemq;

import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import com.ita.pojo.Merchant;
import com.ita.redis.MerchantBlockFactory;
import com.ita.service.MerchantService;
import com.ita.service.impl.MerchantServiceImpl;
import com.ita.util.JsonUtil;

public class BlockedListener implements MessageListener {

	private MerchantService ms = new MerchantServiceImpl();

	/***
	 * update block info
	 */
	public void onMessage(Message message) {
		// TODO Auto-generated method stub
		try {
			TextMessage tmMessage = (TextMessage) message;
			System.out.println(tmMessage.getText());
			Merchant m = JsonUtil.getObjectFromJson(tmMessage.getText(),
					Merchant.class);
			System.out.println(m.getBlock()+" queue send block");
			MerchantBlockFactory.updateMerchant(m.getId(), m);
			
			ms.updateBlock(m.getId(), m.getBlock());
			System.out.println("add update merchant method");
			
			//TODO
			//更新缓存和DB
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
